package com.hs.live.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * @Description: 类型转换的工具类
 * @Author 胡尚
 * @Date: 2024/9/6 14:50
 */
public class ConvertBeanUtils {

    private static Logger log = LoggerFactory.getLogger(ConvertBeanUtils.class);

    public static <T> T convert(Object source, Class<T> target){
        if (source == null){
            return null;
        }
        T targetObj = null;

        try{
            targetObj = target.newInstance();
            BeanUtils.copyProperties(source,targetObj);
        }catch (Exception e){
            log.warn("类型转换异常{}", e.getMessage());
        }
        return targetObj;
    }
}
